home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-comments-post.php < prev    next >
Encoding:
PHP Script  |  2005-05-03  |  2.3 KB  |  63 lines

  1. <?php
  2. require( dirname(__FILE__) . '/wp-config.php' );
  3.  
  4. $comment_post_ID = (int) $_POST['comment_post_ID'];
  5.  
  6. $status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");
  7.  
  8. if ( empty($status->comment_status) ) {
  9.     do_action('comment_id_not_found', $comment_post_ID);
  10.     exit;
  11. } elseif ( 'closed' ==  $status->comment_status ) {
  12.     do_action('comment_closed', $comment_post_ID);
  13.     die( __('Sorry, comments are closed for this item.') );
  14. } elseif ( 'draft' == $status->post_status ) {
  15.     do_action('comment_on_draft', $comment_post_ID);
  16.     exit;
  17. }
  18.  
  19. $comment_author       = trim($_POST['author']);
  20. $comment_author_email = trim($_POST['email']);
  21. $comment_author_url   = trim($_POST['url']);
  22. $comment_content      = trim($_POST['comment']);
  23.  
  24. // If the user is logged in
  25. get_currentuserinfo();
  26. if ( $user_ID ) :
  27.     $comment_author       = addslashes($user_identity);
  28.     $comment_author_email = addslashes($user_email);
  29.     $comment_author_url   = addslashes($user_url);
  30. else :
  31.     if ( get_option('comment_registration') )
  32.         die( __('Sorry, you must be logged in to post a comment.') );
  33. endif;
  34.  
  35. $comment_type = '';
  36.  
  37. if ( get_settings('require_name_email') && !$user_ID ) {
  38.     if ( 6 > strlen($comment_author_email) || '' == $comment_author )
  39.         die( __('Error: please fill the required fields (name, email).') );
  40.     elseif ( !is_email($comment_author_email))
  41.         die( __('Error: please enter a valid email address.') );
  42. }
  43.  
  44. if ( '' == $comment_content )
  45.     die( __('Error: please type a comment.') );
  46.  
  47. $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
  48.  
  49. wp_new_comment($commentdata);
  50.  
  51. setcookie('comment_author_' . COOKIEHASH, stripslashes($comment_author), time() + 30000000, COOKIEPATH);
  52. setcookie('comment_author_email_' . COOKIEHASH, stripslashes($comment_author_email), time() + 30000000, COOKIEPATH);
  53. setcookie('comment_author_url_' . COOKIEHASH, stripslashes($comment_author_url), time() + 30000000, COOKIEPATH);
  54.  
  55. header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
  56. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  57. header('Cache-Control: no-cache, must-revalidate, max-age=0');
  58. header('Pragma: no-cache');
  59.  
  60. $location = (empty($_POST['redirect_to'])) ? $_SERVER["HTTP_REFERER"] : $_POST['redirect_to']; 
  61.  
  62. wp_redirect($location);
  63. ?>